#include <iostream>
#include <string>
#include <cmath>
#include <unordered_map>

using namespace std;

bool is_prime(int num) {
  if (num <= 1) {
    return false;
  }
  if (num <= 3) {
    return true;
  }
  if (num % 2 == 0 || num % 3 == 0) {
    return false;
  }
  for (int i = 5; i * i <= num; i += 6) {
    if (num % i == 0 || num % (i + 2) == 0) {
      return false;
    }
  }
  return true;
}

int find_closest_prime(int num) {
  if (is_prime(num)) {
    return num;
  }

  int step = 1;
  while (true) {
    if (is_prime(num - step)) {
      return num - step;
    }
    if (is_prime(num + step)) {
      return num + step;
    }
    step += 1;
  }
}

int convert_to_number(const string& word1, const string& word2, const string& word3) {
  unordered_map<string, int> number_mapping = {
    {"zero", 0},
    {"one", 1},
    {"two", 2},
    {"three", 3},
    {"four", 4},
    {"five", 5},
    {"six", 6},
    {"seven", 7},
    {"eight", 8},
    {"nine", 9},
  };

  try {
    int digit1 = number_mapping.at(word1);
    int digit2 = number_mapping.at(word2);
    int digit3 = number_mapping.at(word3);
    int number = digit1 * 100 + digit2 * 10 + digit3;
    if (100 <= number && number <= 999) {
      return number;
    } else {
      return -1;
    }
  } catch (const out_of_range& e) {
    return -1;
  }
}

int main() {
  string word1, word2, word3;
  cin >> word1 >> word2 >> word3;

  int number = convert_to_number(word1, word2, word3);
  if (number == -1) {
    cout << "Wrong input" << endl;
  } else {
    cout << find_closest_prime(number) << endl;
  }

  return 0;
}
